import 'package:flutter/material.dart';
import 'package:flutter/src/widgets/framework.dart';
import 'package:get/get.dart';
import 'package:surfaceim/common/values/colors.dart';
import 'package:surfaceim/common/widgets/button.dart';
import 'package:surfaceim/pages/cancellation/controller.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

class CancellationPage extends GetView<CancellationController> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("注销账号"),
      ),
      body: Container(
        width: 1.sw,
        padding: EdgeInsets.fromLTRB(52.w, 20.h, 52.w, 20.h),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          mainAxisAlignment: MainAxisAlignment.start,
          children: [
            Column(
              mainAxisAlignment: MainAxisAlignment.start,
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Text(
                  "是否确定删除您的账户",
                  style: TextStyle(
                      fontWeight: FontWeight.bold,
                      color: Color.fromRGBO(51, 51, 51, 1),
                      fontSize: 40.sp),
                ),
                Container(
                    margin: EdgeInsets.only(top: 21.h),
                    padding: EdgeInsets.only(right: 80.w),
                    child: Text(
                      "我们希望了解怎样可以为你提供更好的体验。未什么要删除你的账户呢？",
                      style: TextStyle(
                          color: Color.fromRGBO(153, 153, 153, 1),
                          fontSize: 28.sp),
                    )),
                Container(
                    margin: EdgeInsets.only(top: 44.h),
                    child: Text(
                      "请选择删除原因",
                      style: TextStyle(
                          fontWeight: FontWeight.bold,
                          color: Color.fromRGBO(51, 51, 51, 1),
                          fontSize: 36.sp),
                    )),
              ],
            ),
            Container(
              height: 5.h,
            ),
            Expanded(
                flex: 5,
                child: SingleChildScrollView(child: _buildChooseItem())),
            Expanded(
                flex: 2,
                child: Center(
                  child: Column(
                    mainAxisAlignment: MainAxisAlignment.center,
                    crossAxisAlignment: CrossAxisAlignment.center,
                    children: [
                      Row(
                        mainAxisAlignment: MainAxisAlignment.center,
                        // crossAxisAlignment: CrossAxisAlignment.center,
                        children: [Text("同意《注销账户须知》")],
                      ),
                      Container(height: 18.h),
                      btnFlatButtonWidget(
                          onPressed: () {},
                          width: 370,
                          height: 80,
                          gbColor: Color.fromRGBO(250, 125, 150, 1),
                          title: "提交并删除账户",
                          fontSize: 30,
                          borderRadius: BorderRadius.all(Radius.circular(90.h)))
                    ],
                  ),
                ))
          ],
        ),
      ),
    );
  }

  /**
   * 生成选择项
   */
  Widget _buildChooseItem() {
    return Obx(() {
      return Column(
          mainAxisAlignment: MainAxisAlignment.start,
          crossAxisAlignment: CrossAxisAlignment.start,
          children: _buildListItem());
    });
  }

  List<Widget> _buildListItem() {
    List<Widget> list = List.empty(growable: true);
    for (var i = 0; i < controller.chooseItem.length; i++) {
      if (controller.chooseItem[i].check) {
        list.add(InkWell(
          onTap: () {
            List<ChooseItem> temp =
                List.empty(growable: true); //需要新建一个对象，否则无法更改
            controller.chooseItem[i].check = !controller.chooseItem[i].check;
            for (var j = 0; j < controller.chooseItem.length; j++) {
              temp.add(controller.chooseItem[j]);
            }
            controller.chooseItem(temp);
          },
          child: Container(
            margin: EdgeInsets.only(top: 60.h, bottom: 18.h),
            child: Row(
              children: [
                Container(
                  height: 30.w,
                  width: 30.w,
                  decoration: BoxDecoration(
                    borderRadius: BorderRadius.all(Radius.circular(15.w)),
                    color: Color.fromRGBO(250, 125, 150, 1),
                  ),
                ),
                Container(
                  width: 25.w,
                ),
                Expanded(
                    flex: 3,
                    child: Text(
                      controller.chooseItem[i].itemName,
                      style: TextStyle(
                          color: Color.fromRGBO(51, 51, 51, 1),
                          fontWeight: FontWeight.w600,
                          fontSize: 30.sp),
                    )),
              ],
            ),
          ),
        ));
      } else {
        list.add(InkWell(
          onTap: () {
            List<ChooseItem> temp =
                List.empty(growable: true); //需要新建一个对象，否则无法更改
            controller.chooseItem[i].check = !controller.chooseItem[i].check;
            for (var j = 0; j < controller.chooseItem.length; j++) {
              temp.add(controller.chooseItem[j]);
            }
            controller.chooseItem(temp);
          },
          child: Container(
            margin: EdgeInsets.only(top: 60.h, bottom: 18.h),
            child: Row(
              children: [
                Container(
                  height: 30.w,
                  width: 30.w,
                  decoration: BoxDecoration(
                      borderRadius: BorderRadius.all(Radius.circular(15.w)),
                      border:
                          Border.all(color: Color.fromRGBO(241, 241, 241, 1))),
                ),
                Container(
                  width: 25.w,
                ),
                Expanded(
                    flex: 3,
                    child: Text(
                      controller.chooseItem[i].itemName,
                      style: TextStyle(
                          color: Color.fromRGBO(51, 51, 51, 1),
                          fontWeight: FontWeight.w600,
                          fontSize: 30.sp),
                    )),
              ],
            ),
          ),
        ));
      }
    }
    return list;
  }
}
